/**
 * 
 */
package com.jie.eclipse.pan.listener;

import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.widgets.Text;

import com.jie.eclipse.pan.dao.QMDao;
import com.jie.eclipse.pan.data.BaseDataEntity;
import com.jie.eclipse.pan.utils.StringHelper;
import com.jie.eclipse.pan.utils.Utils;

/**
 * @author yanjie
 *
 */
public class PJumpCaptionModifyListener extends PFocusListener{
	private Text caption = null;
	/**
	 * @param data
	 */
	public PJumpCaptionModifyListener(BaseDataEntity data) {
		super(data);
	}
	
	public PJumpCaptionModifyListener(Text caption) {
		super(null);
		this.caption = caption;
	}
	
	@Override
	public void focusLost(FocusEvent paramFocusEvent) {
		try{
			Text name = (Text)paramFocusEvent.getSource();
			
			if(this.caption == null && this.data != null){
				this.caption = (Text)data.gpov("caption");
			}
			
			if(this.caption != null
					&& StringHelper.IsNullOrEmpty(caption.getText()) 
					&& !StringHelper.IsNullOrEmpty(name.getText())
					&& (Boolean)name.getData("change")){
				caption.setText(QMDao.getInstance().getCaptionByName(name.getText()));
			}
			name.setData("change", false);
		}catch(Exception e){
			Utils.print("get Caption:\r\n"+e.getMessage());
		}
	}
	
}
